home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctjoc85.arc / SLIMUTIL.ASM < prev    next >
Assembly Source File  |  1985-08-02  |  8KB  |  218 lines

  1.         TITLE   ASMUTIL - Assembly language utilities module
  2.  
  3. TRUE            EQU     01H         ; boolean true
  4. FALSE           EQU     00H         ; boolean false
  5. STCRSR          EQU     02H         ; bios set cursor
  6. SCROLLUP        EQU     06H         ; bios scroll page
  7. VIDEO_IO        EQU     10H         ; bios video i/o
  8. EQUIP           EQU     11H         ; bios equipment selections
  9. SET_CURSOR_TYPE EQU     01H         ; bios cursor type option
  10. BREAKINT        EQU     1BH         ; bios ctrl-break interrupt
  11. SYS_TIMER       EQU     1AH         ; bios time of day interrupt
  12. DOS_FUNCTION    EQU     21H         ; dos function call
  13. GETVECTOR       EQU     35H         ; dos get vector function
  14. SETVECTOR       EQU     25H         ; dos set vector function
  15. STATUS_PORT     EQU     3DAH        ; status port address
  16.  
  17. ASMUTIL SEGMENT PUBLIC 'CODE'
  18.  
  19.         ASSUME  CS:ASMUTIL
  20.         ASSUME  DS:NOTHING
  21.  
  22. BREAKFLAG       DB        0         ; break key hit flag
  23. SAVEBREAK       DD        0         ; saved copy of break vect.
  24.  
  25. ;
  26. ; function tics: word;
  27. ;
  28. ; Returns the low word of the system clock.
  29. ;
  30.         PUBLIC  TICS
  31. TICS            PROC FAR
  32.         MOV     AH,0                ; read clock setting
  33.         INT     SYS_TIMER           ; bios time of day
  34.         MOV     AX,DX               ; return value in ax
  35.         RET
  36. TICS ENDP
  37. ;
  38. ; function equipment: word;
  39. ;
  40. ; Get current bios equipment selections.
  41. ;
  42.         PUBLIC  EQUIPMENT
  43. EQUIPMENT       PROC FAR           ; return bios equipment list
  44.         INT     EQUIP              ; bios equipment routine
  45.         RET                        ; equip list returned in ax
  46. EQUIPMENT       ENDP
  47. ;
  48. ; procedure set_cursor(row, column: integer);
  49. ;
  50. ; Position cursor on screen.  Assumes video page 0.
  51. ;
  52.         PUBLIC  SET_CURSOR
  53. SET_CURSOR      PROC    FAR        ; set cursor on text page
  54.                                    ; with row and col on stack
  55.         PUSH    BP                 ; save frame pointer
  56.         MOV     BP, SP             ; get stack top
  57.         MOV     DH, [BP+8]         ; set dh = row
  58.         MOV     DL, [BP+6]         ; set dl = column
  59.         MOV     BH, 0              ; default to page zero
  60.         MOV     AH,STCRSR          ; set ah = set cursor
  61.         INT     VIDEO_IO           ; call bios video i/o
  62.         POP     BP                 ; restore frame pointer
  63.         RET     4
  64. SET_CURSOR ENDP
  65. ;
  66. ; procedure cursor_disappear
  67. ;
  68. ; Make the cursor invisible.
  69. ;
  70.         PUBLIC  CURSOR_DISAPPEAR
  71. CURSOR_DISAPPEAR PROC FAR
  72.         PUSH    AX                 ; save registers
  73.         PUSH    CX
  74.         MOV     CH,00100000B       ; bit 5 on, bit 6 off
  75.         MOV     AH,SET_CURSOR_TYPE ; set cursor type option
  76.         INT     VIDEO_IO           ; call bios video i/o
  77.         POP     CX                 ; restore registers
  78.         POP     AX
  79.         RET
  80. CURSOR_DISAPPEAR ENDP
  81. ;
  82. ; procedure cursor_reappear
  83. ;
  84. ; Makes the normal flat cursor reappear on the screen.
  85. ;
  86.         PUBLIC  CURSOR_REAPPEAR
  87. CURSOR_REAPPEAR PROC FAR
  88.         PUSH    AX                 ; save registers
  89.         PUSH    CX
  90.         MOV     CH,0BH             ; cursor start reg for mono
  91.         MOV     CL,0CH             ; cursor end reg for mono
  92.         CALL    EQUIPMENT          ; ax = bios equipment flags
  93.         AND     AX,30H             ; mask off mono bits
  94.         CMP     AX,30H             ; is this a mono adapter?
  95.         JE      C1                 ; yes, keep mono start & end
  96.         MOV     CH,06H             ; cursor start reg for color
  97.         MOV     CL,07H             ; cursor end reg for color
  98. C1:     MOV     AH,SET_CURSOR_TYPE ; set cursor type option
  99.         INT     VIDEO_IO           ; call bios video i/o
  100.         POP     CX                 ; restore registers
  101.         POP     AX
  102.         RET
  103. CURSOR_REAPPEAR ENDP
  104. ;
  105. ; procedure clear_screen;
  106. ;
  107. ; Clear video screen.
  108. ;
  109.         PUBLIC  CLEAR_SCREEN
  110. CLEAR_SCREEN    PROC FAR            ; clear screen
  111.         PUSH    BP                  ; save frame pointer
  112.         MOV     BP, SP              ; get stack top
  113.         MOV     AL,0                ; blank entire window
  114.         MOV     CH,0                ; row of upper left corner
  115.         MOV     CL,0                ; col or upper left corner
  116.         MOV     DH,24               ; row of lower right corner
  117.         MOV     DL,79               ; col of lower right corner
  118.         MOV     BH,7                ; normal attributes
  119.         MOV     AH,SCROLLUP         ; AH = scroll active page up
  120.         INT     VIDEO_IO            ; call bios video i/o
  121.         POP     BP                  ; restore frame pointer
  122.         RET
  123. CLEAR_SCREEN    ENDP
  124. ;
  125. ; procedure blast_video_ram(addr:ads of byte;output_byte:byte);
  126. ;
  127. ; Blasts a byte into video ram without causing snow on the
  128. ; color/graphics adapter.
  129. ;
  130.         PUBLIC  BLAST_VIDEO_RAM
  131. BLAST_VIDEO_RAM PROC FAR            ; update video ram w/o snow
  132.         PUSH    BP
  133.         MOV     BP,SP               ; bp = top of stack
  134.         MOV     ES,10[BP]           ; es = base of output byte
  135.         MOV     BX,8[BP]            ; bx = offset of output byte
  136.         MOV     AX,6[BP]            ; ax = output byte
  137.         POP     BP                  ; restore bp
  138.         XCHG    AH,AL               ; ah = output byte
  139.         PUSH    DS                  ; temporarily use ds
  140.         PUSH    ES                  ; set ds to es
  141.         POP     DS                  ;
  142.         MOV     DX, STATUS_PORT     ; dx = status port
  143. SYNC1:  IN      AL, DX              ; al = status register value
  144.         TEST    AL, 1               ; test low bit
  145.         JNZ     SYNC1               ; if not 0 then try again
  146. SYNC2:  IN      AL, DX              ; al = status register value
  147.         TEST    AL, 1               ; test low bit
  148.         JZ      SYNC2               ; if 0 then try again
  149.         MOV     [BX],AH             ; blast byte in video ram
  150.         POP     DS                  ;
  151.         RET     6                   ;
  152. BLAST_VIDEO_RAM ENDP
  153. ;
  154. ; function check_break: boolean;
  155. ;
  156. ; Checks if ctrl-break has been pressed.  It returns TRUE
  157. ; if ctrl-break has been pressed and FALSE if it hasn't.
  158. ;
  159.         PUBLIC  CHECK_BREAK
  160. CHECK_BREAK     PROC FAR
  161.         XOR     AX,AX               ; clear ax
  162.         MOV     AL, BREAKFLAG       ; return value = breakflag
  163.         MOV     BREAKFLAG, FALSE    ; reset break flag
  164.         RET
  165. CHECK_BREAK     ENDP
  166. ;
  167. ; procedure install_break_handler;
  168. ;
  169. ; Installs a ctrl-break interrupt handler.  It also
  170. ; saves the address of the former break handler.
  171. ;
  172.         PUBLIC  INSTALL_BREAK_HANDLER
  173. INSTALL_BREAK_HANDLER PROC FAR
  174.         PUSH    DS
  175.         MOV     AL,BREAKINT         ; al = dos break interrupt
  176.         MOV     AH,GETVECTOR        ; ah = dos get vector funct.
  177.         INT     DOS_FUNCTION        ; call dos
  178.         MOV     WORD PTR SAVEBREAK,BX   ; save off. of int. vec.
  179.         MOV     WORD PTR SAVEBREAK+2,ES ; save base of int. vec.
  180.         MOV     AL,BREAKINT         ; al = dos break interrupt
  181.         MOV     AH,SETVECTOR        ; ah = dos set vector funct.
  182.         MOV     DX,OFFSET BREAK_HANDLER ; dx = off. break hndlr
  183.         MOV     BX,CS                   ; bx = this segment
  184.         MOV     DS,BX                   ; ds = this segment
  185.         INT     DOS_FUNCTION            ; call dos
  186.         POP     DS
  187.         RET
  188. INSTALL_BREAK_HANDLER  ENDP
  189. ;
  190. ; interrupt handler break_handler;
  191. ;
  192. ; This is invoked by the bios when ctrl_break is pressed.
  193. ;
  194. BREAK_HANDLER   PROC FAR
  195.         MOV     BREAKFLAG, TRUE     ; breakflag = ctrl-break
  196.         IRET                        ;  was pressed
  197. BREAK_HANDLER   ENDP
  198. ;
  199. ; procedure remove_break_handler;
  200. ;
  201. ; Restores the previous ctrl-break handler.
  202. ;
  203.         PUBLIC  REMOVE_BREAK_HANDLER
  204. REMOVE_BREAK_HANDLER PROC FAR
  205.         PUSH    DS
  206.         MOV     AL,BREAKINT         ; al = dos break interrupt
  207.         MOV     AH,SETVECTOR        ; ah = dos set vector funct.
  208.         MOV     DX,WORD PTR SAVEBREAK   ; dx = saved offset
  209.         MOV     BX,WORD PTR SAVEBREAK+2 ; bx = saved base
  210.         MOV     DS,BX                   ; ds = saved base
  211.         INT     DOS_FUNCTION            ; call dos
  212.         POP     DS
  213.         RET
  214. REMOVE_BREAK_HANDLER ENDP
  215.  
  216. ASMUTIL ENDS
  217.         END
  218.